package controller

import (
	"github.com/gin-gonic/gin"
	"managementsystem/common"
	"managementsystem/pkg/utils"
)

func GinDeleteInfo(ctx *gin.Context) {

	db := common.Connect()
	defer db.Close()

	var data utils.S
	ctx.Bind(&data)
	if isSnoExists(db, data.Sno) == false {
		ctx.JSON(200, gin.H{"msg": "学号不存在, 删除失败"})
		return
	}
	//数据验证
	if len(data.Sno) != 6 {
		ctx.JSON(200, gin.H{"code": 200, "msg": "学号必须6位"})
		return
	}
	//返回结果
	common.DeleteInfo(db, data)
	ctx.JSON(200, gin.H{"msg": "删除成功"})
}
